package cn.s1995.sloth.bizs.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.s1995.sloth.bizs.constant.BizCst;
import cn.s1995.sloth.bizs.constant.CacheNames;
import cn.s1995.sloth.bizs.entity.UserCollection;
import cn.s1995.sloth.bizs.mapper.UserCollectionMapper;
import cn.s1995.sloth.bizs.service.UserCollectionService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
 * 用户收藏记录
 *
 * @author sloth
 * @date 2023-12-23 09:31:27
 */
@Service
public class UserCollectionServiceImpl extends ServiceImpl<UserCollectionMapper, UserCollection> implements UserCollectionService {

	@Override
	@Cacheable(value = CacheNames.userCollectionProd, key= "#uid")
	public Set<Long> getUserCollectProdIds(Long uid) {
		List<UserCollection> list = this.list(
				Wrappers.lambdaQuery(UserCollection.class)
						.eq(UserCollection::getType, BizCst.UserCollection.Type.prod)
						.eq(UserCollection::getUid, uid)
			);
	if(ObjectUtil.isNotEmpty(list))
		return list.stream()
				.map(e -> e.getBindId())
				.collect(Collectors.toSet());
	return new HashSet<>();
	}

	@Override
	@CachePut(value = CacheNames.userCollectionProd, key= "#uid")
	public Set<Long> updateUserCollectProdIds(Long uid, Set<Long> userCollectProdIds) {
		return userCollectProdIds;
	}
}
